package org.linuxsogood.boot.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author honway.liu
 * @date 2019/10/18 9:44 PM
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class Demo {

    public static void main(String[] args) throws IOException {
       // String url = "http://218.14.207.76:8210/tt/business/buildingRooms_xml.asp?functiontype=6&sid=0.14751397589198856&client_showMode=&client_stanID=1610&client_realtypeID=-1&client_mainTable=unrelatedresource&client_mainno=0&client_buildID=772100&floorStart=-100&floorEnd=-100&roomNoStart=-100&roomNoEnd=-100&cancelBldroomShow=3&client_showiscansale=0&client_showRoomCond=&pmBldRoomID=undefined";
       /* URL url1 = new URL(url);
        URLConnection urlConnection = url1.openConnection();
        InputStream inputStream = urlConnection.getInputStream();
        BufferedInputStream stream = new BufferedInputStream(inputStream);
        InputStreamReader reader = new InputStreamReader(stream);
        int c;
        while ( (c = reader.read()) != -1) {
            System.out.println((char) c);
        }*/
        /*Connection connect = Jsoup.connect(url);
        Document document = Jsoup.connect(url).
                header("referer","http://218.14.207.76:8210/tt/business/bldr_vdetail-NzcyMTAw-gs-.html")
                .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36")
                .cookie("ASPSESSIONIDSARCBCCS", "FJFDENHAFDEKEJGDDCLKOPMN; ASPSESSIONIDQARCBCCS=IJFDENHAFGFCMONCCHMHJEDB")
                .post();
        document.charset(Charset.forName("gb2312"));
        System.out.println(document);*/

        String url = "http://218.14.207.76:8210/tt/business/bldr_vdetail-NzcyNDE1-gs-.html";
        Document document = Jsoup.connect(url).
                header("referer","http://218.14.207.76:8210/tt/business/bldr_vdetail-NzcyMTAw-gs-.html")
                .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36")
                .cookie("ASPSESSIONIDSARCBCCS", "FJFDENHAFDEKEJGDDCLKOPMN; ASPSESSIONIDQARCBCCS=IJFDENHAFGFCMONCCHMHJEDB")
                .post();

        Elements elements = document.select("script");
        for (Element element : elements) {
            String x = element.toString();
            String regex = "\\s\\S.+client_stanID='(\\d+?)'";
            Matcher matcher = Pattern.compile(regex).matcher(x);
            while (matcher.find()) {
                System.out.println(matcher.group(1));
            }
        }


        //System.out.println(document.body().text());

    }
}
